﻿@model Tau.ViewModels.ProductList

@{
    ViewBag.Title = "Index";
}

<div id="addEdit" title="Add/Edit Product" style="display:none"></div>

<h2>Products &nbsp; &nbsp; <a href="#" class="addNew" onclick="popupAddEdit();" style="cursor:pointer"> + Add New Product</a> </h2>



<div id="productList">
    @Html.Partial("ProductList", Model)
</div>

<script type="text/javascript" charset="utf-8">

    function sortList(propertyName) {

        var productList = $('#productList');

        productList.fadeOut('normal', function () {
            var urlAction = '@Url.Action("GetSortedList", "ProductAdmin")';
            urlAction = urlAction + "?sortBy=" + propertyName;

            productList.load(urlAction, function () {
                productList.fadeIn(100);
            });
        });
    }

    function deleteProduct(productId, productName) {

        showYesNoDialog(
                        "Are you sure you want to delete this product (" + productName + ")?", 
                        function () {
                            location.href = '@Url.Action("Delete", "ProductAdmin")' + '?productId=' + productId;
                        });
    }

    function popupAddEdit(editId) {

        showProgress();
        
        var url = '@Url.Action("AddEditProduct", "ProductAdmin")';

        if (editId != null && editId > 0) {
            url = url + "?productId=" + editId;
        }
        
        $("#addEdit").load(url, function () {

            $("#addEdit").dialog({
                autoOpen: true,
                height: 650,
                width: 950,
                modal: true
            });
            hideProgress();
        });
       
        
    }
        
</script>



